package com.industrial.operation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationMetric;
import com.industrial.operation.service.IOperationMetricService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 重点运行企业（按市分）Controller
 * 
 * @author Zhou_S
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/metric")
public class OperationMetricController extends BaseController
{
    @Autowired
    private IOperationMetricService operationMetricService;

    /**
     * 查询重点运行企业（按市分）列表
     */
    @RequiresPermissions("metric:metric:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationMetric operationMetric)
    {
        startPage();

        if(StringUtils.isNotBlank(operationMetric.getYearMonth())){
            String yearMohth=operationMetric.getYearMonth()+"-01";
            operationMetric.setYearMonth(yearMohth);
        }
        List<OperationMetric> list = operationMetricService.selectOperationMetricList(operationMetric);
        return getDataTable(list);
    }

    /**
     * 导出重点运行企业（按市分）列表
     */
    @RequiresPermissions("metric:metric:export")
    @Log(title = "重点运行企业（按市分）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationMetric operationMetric)
    {
        List<OperationMetric> list = operationMetricService.selectOperationMetricList(operationMetric);
        ExcelUtil<OperationMetric> util = new ExcelUtil<OperationMetric>(OperationMetric.class);
        util.exportExcel(response, list, "重点运行企业（按市分）数据");
    }

    /**
     * 获取重点运行企业（按市分）详细信息
     */
    @RequiresPermissions("metric:metric:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationMetricService.selectOperationMetricByBaseId(baseId));
    }

    /**
     * 新增重点运行企业（按市分）
     */
    @RequiresPermissions("metric:metric:add")
    @Log(title = "重点运行企业（按市分）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationMetric operationMetric)
    {
        return toAjax(operationMetricService.insertOperationMetric(operationMetric));
    }

    /**
     * 修改重点运行企业（按市分）
     */
    @RequiresPermissions("metric:metric:edit")
    @Log(title = "重点运行企业（按市分）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationMetric operationMetric)
    {
        return toAjax(operationMetricService.updateOperationMetric(operationMetric));
    }

    /**
     * 删除重点运行企业（按市分）
     */
    @RequiresPermissions("metric:metric:remove")
    @Log(title = "重点运行企业（按市分）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationMetricService.deleteOperationMetricByBaseIds(baseIds));
    }
}
